package cc.rengu.igas.bsps.common.dao.impl;

import cc.rengu.igas.bsps.common.dao.FundsReconSummaryInfoQueryMapper;
import cc.rengu.igas.bsps.common.entity.FundCheckStatis;
import cc.rengu.oltp.service.common.constant.AppConfigConstant;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.utility.bean.PageInfo;
import cc.rengu.oltp.utility.bean.PageResult;
import cc.rengu.oltp.utility.util.DbsUtil;
import cc.rengu.oltp.utility.util.XmlConfigUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.cache.UnifiedCache;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;

/**
 * 资金对账汇总信息查询正式表接口类
 * Created by yuhongwen
 */
public class FundsReconSummaryInfoQueryMapperImpl implements FundsReconSummaryInfoQueryMapper {
    private RgLogger rglog = RgLog.getLogger(this.getClass().getName());
    private String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.CSMC_POOL_NAME);


    @Override
    public FundCheckStatis selectFundCheckStatis(String instId, String mchntNo, String settleDate) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.CSMC_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "selectFundCheckStatis");
        FundCheckStatis fundCheckStatis = new FundCheckStatis();
        fundCheckStatis.setInstId(instId);
        if (null != mchntNo && !mchntNo.isEmpty()) {
            fundCheckStatis.setMchntNo(mchntNo);
        }
        if (null != settleDate && !settleDate.isEmpty()) {
            fundCheckStatis.setMchntSettleDate(settleDate);
        }
        int iReturnCode = dbsUtil.dbsExecuteSql(sqlStr, fundCheckStatis, fundCheckStatis);
        if (0 != iReturnCode) {
            rglog.error("资金对账汇总信息查询失败");
            return null;
        }
//        List<Object> objectList = dbsUtil.dbsFetchLimitListData(sqlStr, payOrderInfo, PayOrderInfo.class);
//        if (null == objectList || objectList.isEmpty()) {
//            rglog.error("订单信息查询失败");
//            return null;
//        }
        return fundCheckStatis;
    }

    @Override
    public PageResult selectFundCheckStatisPage(String instId, String mchntNo, String startDate, String endDate, PageInfo pageInfo) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.CSMC_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "selectFundCheckStatisPage");
        FundCheckStatis fundCheckStatis = new FundCheckStatis();
        fundCheckStatis.setInstId(instId);
        if (null != mchntNo && !mchntNo.isEmpty()) {
            fundCheckStatis.setMchntNo(mchntNo);
        }
        if (null != startDate && !startDate.isEmpty()) {
            fundCheckStatis.setMchntSettleDate(startDate);
        }
        if (null != endDate && !endDate.isEmpty()) {
            fundCheckStatis.setRemark1(endDate);
        }
        return dbsUtil.dbsFetchPageListData(sqlStr, fundCheckStatis, FundCheckStatis.class, pageInfo);
    }


}
